library(tidyverse)
## ── Attaching packages ─────────────────────────────────────── tidyverse 1.3.1 ──
## ✓ ggplot2 3.3.5 ✓ purrr 0.3.4
## ✓ tibble 3.1.4 ✓ dplyr 1.0.7
## ✓ tidyr 1.1.3 ✓ stringr 1.4.0
## ✓ readr 2.0.1 ✓ forcats 0.5.1
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## x dplyr::filter() masks stats::filter()
## x dplyr::lag() masks stats::lag()
library(ggplot2)
library(gplots)
##
## Attaching package: 'gplots'
## The following object is masked from 'package:stats':
##
## lowess
library(dplyr)
library(readr)
library(gganimate)
library(gifski)
library(plotly)
##
## Attaching package: 'plotly'
## The following object is masked from 'package:ggplot2':
##
## last_plot
## The following object is masked from 'package:stats':
##
## filter
## The following object is masked from 'package:graphics':
##
## layout
library(readxl)
X3_pointers <- read_excel("Downloads/3 pointers.xlsx") #Takes file from downloads and names it as a dataset.
`3PA` <- ggplot(X3_pointers, aes(x=`Season`, y=`3PA`))+ #Creating plot from the data given, with Season on x-axis and 3PA on y-axis.
geom_line(aes(group=5, col="red"))+ #Creates a line plot using the data.
theme(legend.position = "None")+ #Makes it so there is no legend on the graph.
ggtitle("3PA per Game by Season")+ #Titling the graph.
xlab("Season")+ylab("Average 3PA per Game")+ #Labeling each axis.
transition_reveal(Season) #Creates the animation to go smoothly, rather than appearing point by point.
`3PA`
animate(`3PA`, duration = 9, fps = 3, width=500, height=400, renderer = gifski_renderer()) #Animates the graph as a whole, duration being 9 seconds and frames per second being 3. The width and height are the dimensions of the graph.
anim_save("3PAAnimated2.gif") #Saves the animation as a file.
library(readxl)
X3_pointers <- read_excel("Downloads/3 pointers.xlsx") #Takes file from downloads and names it as a dataset.
`3PM` <- ggplot(X3_pointers, aes(x=`Season`, y=`3PM`))+ #Creating plot from the data given, with Season on x-axis and 3PM on y-axis.
geom_line(aes(group=5, color="red"))+ #Creates a line plot using the data.
theme(legend.position = "None")+ #Makes it so there is no legend on the graph.
ggtitle("3PM per Game by Season")+ #Titling the graph.
xlab("Season")+ylab("Average 3PM per Game")+ #Labeling each axis.
transition_reveal(Season) #Creates the animation to go smoothly, rather than appearing point by point.
`3PM`
animate(`3PM`, duration = 9, fps = 3, width=500, height=400, renderer = gifski_renderer()) #Animates the graph as a whole, duration being 9 seconds and frames per second being 3. The width and height are the dimensions of the graph.
anim_save("3PMAnimated.gif") #Saves the animation as a file.
library(readxl)
X3_pointers <- read_excel("Downloads/3 pointers.xlsx") #Takes file from downloads and names it as a dataset.
`3P%` <- ggplot(X3_pointers, aes(x=`Season`, y=`3P%`))+ #Creating plot from the data given, with Season on x-axis and 3P% on y-axis.
geom_line(aes(group=5, color="red"))+ #Creates a line plot using the data.
theme(legend.position = "None")+ #Makes it so there is no legend on the graph.
ggtitle("3P% by Season")+ #Titling the graph.
xlab("Season")+ylab("Average 3P%")+ #Labeling each axis.
transition_reveal(Season) #Creates the animation to go smoothly, rather than appearing point by point.
`3P%`
animate(`3P%`, duration = 9, fps = 3, width=500, height=400, renderer = gifski_renderer()) #Animates the graph as a whole, duration being 9 seconds and frames per second being 3. The width and height are the dimensions of the graph.
anim_save("3PM%nimated.gif") #Saves the animation as a file.
X3toW <- read_excel("Downloads/Data Science Final.xlsx") #Takes file from downloads and names it as a dataset.
pf <- ggplot(X3toW, aes(x=`3P%`, y=`Win %`, col= Team ))+ #Creates plot using data, with 3P% on x-axis and Win% on y-axis. Color coordinates each team.
geom_point(show.legend = FALSE, alpha=0.75) #Creates point graph, without having the original legend. The alpha command sets the transparency of each point.
ggplotly(pf) #Takes the plot and makes it interactive, showing what each point represents.
Here, we can look at the overall correlation between 3P% and teams Win % over the past 10 NBA seasons. Although the correlation isn’t too strong, it is obvious that there is a relationship between shooting a higher 3P%, and ultimately the number of games you win. This shows that teams that to shoot the best from behind the arc, the more likely they are to win more games.